package cn.hdu.liang.core.service.order;

import cn.hdu.liang.core.bean.order.Detail;
import cn.hdu.liang.core.dao.order.DetailDao;
import cn.hdu.liang.core.query.order.DetailQuery;
import cn.itcast.common.page.Pagination;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单子项(订单详情)
 */
@Service
@Transactional
public class DetailServiceImpl implements DetailService {

    @Resource
    DetailDao detailDao;

    public Integer addDetail(Detail detail) {
        return detailDao.addDetail(detail);
    }

    @Transactional(readOnly = true)
    public Detail getDetailByKey(Integer id) {
        return detailDao.getDetailByKey(id);
    }

    @Transactional(readOnly = true)
    public List<Detail> getDetailsByKeys(List<Integer> idList) {
        return detailDao.getDetailsByKeys(idList);
    }

    public Integer deleteByKey(Integer id) {
        return detailDao.deleteByKey(id);
    }

    public Integer deleteByKeys(List<Integer> idList) {
        return detailDao.deleteByKeys(idList);
    }

    public Integer updateDetailByKey(Detail detail) {
        return detailDao.updateDetailByKey(detail);
    }

    @Transactional(readOnly = true)
    public Pagination getDetailListWithPage(DetailQuery detailQuery) {
        Pagination p = new Pagination(detailQuery.getPageNo(), detailQuery.getPageSize(), detailDao.getDetailListCount(detailQuery));
        p.setList(detailDao.getDetailListWithPage(detailQuery));
        return p;
    }

    @Transactional(readOnly = true)
    public List<Detail> getDetailList(DetailQuery detailQuery) {
        return detailDao.getDetailList(detailQuery);
    }
}
